package org.anderground.editor.gui.properties;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.anderground.core.util.ColorUtils;

@SuppressWarnings("serial")
public class ColorPanel extends JPanel {

	private Color color;

	public ColorPanel(int color) {
		this(color, ColorUtils.format(color));
	}

	public ColorPanel(int color, String text) {
		this.color = new Color(color);
		JLabel label = new JLabel("<html><b><font color="
				+ ColorUtils.format(new Color(~color).getRGB()) + ">" + text
				+ "</font></b></html>");
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		add(label);
	}

	@Override
	public void paintComponent(Graphics g) {
		Rectangle r = new Rectangle(this.getSize());
		g.setColor(color);
		((Graphics2D) g).fill(r);
	}

}
